<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<div class="content-wrap">
        <div class="wrapper" style="bottom: 50px;">
            <ul class="nav nav-tabs">
                <li>
                    <a href="#" >库存列表</a>
                </li>
            </ul>
            <section class="panel panel-default">
                <div class="panel-body">
                    <div class="col-lg-12">
                        <table id="stockTable" class="table table-bordered mg-t datatable">
                            <thead>
                            <tr>
                                <th hidden>id</th>
                                <th>批次</th>
                                <th>有效期</th>
                                <th>大包装账面数</th>
                                <th>小包装库存量</th>
                                <th>盘点小包装</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${expStockList}" var="expStock">
                            <tr >
                                <td hidden>${expStock.id}</td>
                                <td>${expStock.batchNo}</td>
                                <td><fmt:formatDate value="${expStock.expireDate}" pattern="yyyy-MM-dd"></fmt:formatDate> </td>
                                <td>${expStock.quantity/expStock.packageNum}</td>
                                <td>${expStock.quantity}</td>
                                <td><input name="quantity" htmlEscape="false" maxlength="50" class="form-control" data-parsley-required="true" data-parsley-type="number" value="${expStock.quantity}"></td>
                            </tr>
                            </c:forEach>
                        </table>
                        &nbsp; <input class="btn btn-primary" value="保存" onclick="saveRows()">&nbsp;
                    </div>
                </div>
            </section>
        </div>
    </div>
<script>
    function saveRows(){
        var tables=document.getElementById("stockTable");
        //组装传回的list
        var expInventoryCheckList=[];
        for (var i=1;i<tables.rows.length;i++){
            var expInventoryCheck={};
            expInventoryCheck.stockId=tables.rows[i].cells[0].innerHTML;
            expInventoryCheck.maxQuantity=tables.rows[i].cells[4].innerHTML;
            expInventoryCheck.minQuantity=tables.rows[i].cells[4].innerHTML;
            expInventoryCheck.actualQuantity=tables.rows[i].cells[5].childNodes[0].value;
            expInventoryCheckList.push(expInventoryCheck);
        }
        var expInventoryCheckListJson = JSON.stringify(expInventoryCheckList);
        $.ajax({
            type: "POST",
            url: '${ctx}/csm/expInventoryCheck/saveList',
            data:expInventoryCheckListJson,
            'contentType': 'application/json',
            dataType: "json",
            success: function (data) {
                if (data.code = "success") {
                    toastr.success('消耗品盘点成功');
                    $('#btnSubmit').trigger("click");
                } else {
                    alert("error");
                }
            },
            error: function (data) {
                toastr.error('网络连接错误,请检查网络');
            }
        });
    }

</script>